package com.caimiao.miao.library.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.text.TextUtils;

import com.caimiao.miao.http.retorfit.HttpConfig;
import com.caimiao.miao.library.database.DBHelperFactory;
import com.caimiao.miao.library.database.table.DeviceDBHelper;
import com.caimiao.miao.library.utils.sys.DeviceUtil;
import com.caimiao.miao.library.utils.tip.LogUtil;

public class QrBmpUtil {
    private static volatile Bitmap mQrBmp;
    private static String url = "%s/wx/auth?alias=%s";

    public static Bitmap getQrBmp(Context context) {
        return getQrBmp(context, 200, 200);
    }

    public static synchronized Bitmap getQrBmp(Context context, int width, int height) {
        if (mQrBmp == null) {
            String extra = String.format(url, HttpConfig.getBaseUrl(),  DeviceUtil.getDeviceId(context));
            LogUtil.e("PAGE", "qrCode: " + extra);
            mQrBmp = QRCodeUtil.createQRCodeBitmap(extra, width, height);
        }
        return mQrBmp;
    }

    public static void clear() {
        mQrBmp = null;
    }
}
